const app = getApp();

export const request = ({
  url,
  method,
  data,
  headers
})=> {

  wx.showLoading({
    title: '加载中',
  })

  if(!headers){
    headers = {}
  }
  headers.openId = app.globalData.openId
  return new Promise((resolve, reject) => {
    wx.request({
      url: app.globalData.url + url,
      header: headers,
      method: method,
      data: data,
      timeout: 60000,
      success: res => {
        wx.hideLoading();
        resolve(res.data);
      },
      fail: res => {
        wx.hideLoading();
        wx.showToast({
          icon: "error",
          title: "网络繁忙，请稍后",
          duration: 1000,
          mask: true
        });
        reject(res);
      }
    });
  });

}